#define  _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <assert.h>

size_t My_strlen1(const char* dest)
{
	size_t count = 0;
	while (*dest)
	{
		count++;
		dest++;
	}

	return count;
}
size_t My_strlen2(const char* dest)
{
	char* tail = dest;
	while (*tail++)
	{
		;
	}
	tail--;

	return tail - dest;
}
size_t My_strlen3(const char* dest)
{
	if (*dest == '\0')
	{
		return 0;
	}
	else
	{
		return 1 + My_strlen3(dest + 1);
	}
}
char* My_strcpy(char* dest, const char* src)
{
	assert(dest && src);
	char* ret = dest;

	while (*dest++ = *src++)
	{
		;
	}

	return ret;
}
char* My_strcat(char* dest, const char* src)
{
	assert(dest && src);
	char* ret = dest;

	while (*dest)
	{
		dest++;
	}

	while (*dest++ = *src++)
	{
		;
	}

	return ret;
}
int My_strcmp(const char* s1, const char* s2)
{
	assert(s1 && s2);

	while (*s1 == *s2)
	{
		if (*s1 == '\0')
		{
			return 0;
		}

		s1++;
		s2++;
	}
	if (*s1 > *s2)
		return 1;
	else
		return - 1;
}
char* My_strstr1(const char* str1, const char* str2)
{
	assert(str1 && str2);
	char* s1 = str1;
	char* s2 = str2;
	char* cur = str1;

	while (*cur)
	{
		s1 = cur;
		s2 = str2;
		while (*s1 && *s2 && (*s1 == *s2))
		{
			s1++;
			s2++;
		}
		if (*s2 == '\0')
		{
			return cur;
		}

		cur++;
	}

	return NULL;
}
char* My_strstr(const char* str1, const char* str2)
{
	assert(str1 && str2);
	const char* s1 = str1;
	const char* s2 = str2;
	const char* cur = str1;

	while (*cur)
	{
		s1 = cur;
		s2 = str2;
		while (*s1 && *s2 && (*s1 == *s2))
		{
			s1++;
			s2++;
		}
		if (*s2 == '\0')
		{
			return (char*)cur;
		}

		cur++;
	}

	return NULL;
}
int main()
{
	char ch[] = "acdabcdef";
	char ch1[20] = { 0 };
	char ch2[] = "xxxxx";
	char ch3[] = "abc";

	//printf("%u\n", My_strlen1(ch));
	//printf("%u\n", My_strlen2(ch));
	//printf("%u\n", My_strlen3(ch));
	//printf("%s\n", My_strcpy(ch1, ch));
	//printf("%d\n", My_strcmp(ch1, ch));
	//printf("%s\n", My_strcat(ch1, ch2));
	printf("%s\n",My_strstr1(ch, ch3));

	return 0;
}